#!/usr/bin/python
from transformers import AutoModelForQuestionAnswering,AutoTokenizer,pipeline
cqa_data = AutoModelForQuestionAnswering.from_pretrained('uer/roberta-base-chinese-extractive-qa')
cqa_tokenizer = AutoTokenizer.from_pretrained('uer/roberta-base-chinese-extractive-qa')
cqa_model = pipeline('question-answering', model=cqa_data, tokenizer=cqa_tokenizer)
question_context = {}
question_context['question'] = "著名诗歌《假如生活欺骗了你》的作者是"
question_context['context'] = "普希金从那里学习人民的语言，吸取了许多有益的养料，这一切对普希金后来的创作产生了很大的影响。这两年里，普希金创作了不少优秀的作品，如《囚徒》、《致大海》、《致凯恩》和《假如生活欺骗了你》等几十首抒情诗，叙事诗《努林伯爵》，历史剧《鲍里斯·戈都诺夫》，以及《叶甫盖尼·奥涅金》前六章。"
answer_confidence = cqa_model(question_context)["score"]
print(answer_confidence)